package scalaLearning.part4

object PartialFunc2 {
  def main(args: Array[String]): Unit = {
    //使用偏函数解决
    val list = List(1, 2, 3, 4, "abc")
    val partialfunc: PartialFunction[Any, Int] = new PartialFunction[Any, Int] {
      override def isDefinedAt(x: Any): Boolean = x.isInstanceOf[Int]

      override def apply(v1: Any): Int = {
        v1.asInstanceOf[Int] + 1
      }
    }
    //使用偏函数
    //偏函数不能使用map，要使用collect
    val list2: List[Int] = list.collect(partialfunc)
    println("list2="+list2)

    //
  }
}
